home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InvalidObjectException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.Enumeration;
-
- public final class Inet6Address extends InetAddress {
- static final int INADDRSZ = 16;
- private transient int cached_scope_id = 0;
- byte[] ipaddress;
- private int scope_id = 0;
- private boolean scope_id_set = false;
- private transient NetworkInterface scope_ifname = null;
- private boolean scope_ifname_set = false;
- private static final long serialVersionUID = 6880410070516793377L;
- private static final int INT16SZ = 2;
- private String ifname;
-
- Inet6Address() {
- this.hostName = null;
- this.ipaddress = new byte[16];
- this.family = 2;
- }
-
- Inet6Address(String var1, byte[] var2, int var3) {
- this.hostName = var1;
- if (var2.length == 16) {
- this.family = 2;
- this.ipaddress = (byte[])(([B)var2).clone();
- }
-
- if (var3 >= 0) {
- this.scope_id = var3;
- this.scope_id_set = true;
- }
-
- }
-
- Inet6Address(String var1, byte[] var2) {
- try {
- this.initif(var1, var2, (NetworkInterface)null);
- } catch (UnknownHostException var4) {
- }
-
- }
-
- Inet6Address(String var1, byte[] var2, NetworkInterface var3) throws UnknownHostException {
- this.initif(var1, var2, var3);
- }
-
- Inet6Address(String var1, byte[] var2, String var3) throws UnknownHostException {
- this.initstr(var1, var2, var3);
- }
-
- public static Inet6Address getByAddress(String var0, byte[] var1, NetworkInterface var2) throws UnknownHostException {
- if (var0 != null && var0.length() > 0 && var0.charAt(0) == '[' && var0.charAt(var0.length() - 1) == ']') {
- var0 = var0.substring(1, var0.length() - 1);
- }
-
- if (var1 != null && var1.length == 16) {
- return new Inet6Address(var0, var1, var2);
- } else {
- throw new UnknownHostException("addr is of illegal length");
- }
- }
-
- public static Inet6Address getByAddress(String var0, byte[] var1, int var2) throws UnknownHostException {
- if (var0 != null && var0.length() > 0 && var0.charAt(0) == '[' && var0.charAt(var0.length() - 1) == ']') {
- var0 = var0.substring(1, var0.length() - 1);
- }
-
- if (var1 != null && var1.length == 16) {
- return new Inet6Address(var0, var1, var2);
- } else {
- throw new UnknownHostException("addr is of illegal length");
- }
- }
-
- private void initstr(String var1, byte[] var2, String var3) throws UnknownHostException {
- try {
- NetworkInterface var4 = NetworkInterface.getByName(var3);
- if (var4 == null) {
- throw new UnknownHostException("no such interface " + var3);
- } else {
- this.initif(var1, var2, var4);
- }
- } catch (SocketException var5) {
- throw new UnknownHostException("SocketException thrown" + var3);
- }
- }
-
- private void initif(String var1, byte[] var2, NetworkInterface var3) throws UnknownHostException {
- this.hostName = var1;
- if (var2.length == 16) {
- this.family = 2;
- this.ipaddress = (byte[])(([B)var2).clone();
- }
-
- if (var3 != null) {
- this.scope_ifname = var3;
- this.scope_ifname_set = true;
- this.scope_id = this.deriveNumericScope(var3);
- this.scope_id_set = true;
- }
-
- }
-
- private boolean differentLocalAddressTypes(Inet6Address var1) {
- if (this.isLinkLocalAddress() && !var1.isLinkLocalAddress()) {
- return false;
- } else {
- return !this.isSiteLocalAddress() || var1.isSiteLocalAddress();
- }
- }
-
- private int deriveNumericScope(NetworkInterface var1) throws UnknownHostException {
- Enumeration var2 = var1.getInetAddresses();
-
- while(var2.hasMoreElements()) {
- InetAddress var3 = (InetAddress)var2.nextElement();
- if (var3 instanceof Inet6Address) {
- Inet6Address var4 = (Inet6Address)var3;
- if (this.differentLocalAddressTypes(var4)) {
- return var4.scope_id;
- }
- }
- }
-
- throw new UnknownHostException("no scope_id found");
- }
-
- private int deriveNumericScope(String var1) throws UnknownHostException {
- Enumeration var2;
- try {
- var2 = NetworkInterface.getNetworkInterfaces();
- } catch (SocketException var7) {
- throw new UnknownHostException("could not enumerate local network interfaces");
- }
-
- while(var2.hasMoreElements()) {
- NetworkInterface var3 = (NetworkInterface)var2.nextElement();
- if (var3.getName().equals(var1)) {
- Enumeration var4 = var3.getInetAddresses();
-
- while(var4.hasMoreElements()) {
- InetAddress var5 = (InetAddress)var4.nextElement();
- if (var5 instanceof Inet6Address) {
- Inet6Address var6 = (Inet6Address)var5;
- if (this.differentLocalAddressTypes(var6)) {
- return var6.scope_id;
- }
- }
- }
- }
- }
-
- throw new UnknownHostException("No matching address found for interface : " + var1);
- }
-
- private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- this.scope_ifname = null;
- this.scope_ifname_set = false;
- var1.defaultReadObject();
- if (this.ifname != null && !"".equals(this.ifname)) {
- try {
- this.scope_ifname = NetworkInterface.getByName(this.ifname);
-
- try {
- this.scope_id = this.deriveNumericScope(this.scope_ifname);
- } catch (UnknownHostException var3) {
- assert false;
- }
- } catch (SocketException var4) {
- }
-
- if (this.scope_ifname == null) {
- this.scope_id_set = false;
- this.scope_ifname_set = false;
- this.scope_id = 0;
- }
- }
-
- this.ipaddress = (byte[])this.ipaddress.clone();
- if (this.ipaddress.length != 16) {
- throw new InvalidObjectException("invalid address length: " + this.ipaddress.length);
- } else if (this.family != 2) {
- throw new InvalidObjectException("invalid address family type");
- }
- }
-
- public boolean isMulticastAddress() {
- return (this.ipaddress[0] & 255) == 255;
- }
-
- public boolean isAnyLocalAddress() {
- byte var1 = 0;
-
- for(int var2 = 0; var2 < 16; ++var2) {
- var1 |= this.ipaddress[var2];
- }
-
- return var1 == 0;
- }
-
- public boolean isLoopbackAddress() {
- byte var1 = 0;
-
- for(int var2 = 0; var2 < 15; ++var2) {
- var1 |= this.ipaddress[var2];
- }
-
- return var1 == 0 && this.ipaddress[15] == 1;
- }
-
- public boolean isLinkLocalAddress() {
- return (this.ipaddress[0] & 255) == 254 && (this.ipaddress[1] & 192) == 128;
- }
-
- public boolean isSiteLocalAddress() {
- return (this.ipaddress[0] & 255) == 254 && (this.ipaddress[1] & 192) == 192;
- }
-
- public boolean isMCGlobal() {
- return (this.ipaddress[0] & 255) == 255 && (this.ipaddress[1] & 15) == 14;
- }
-
- public boolean isMCNodeLocal() {
- return (this.ipaddress[0] & 255) == 255 && (this.ipaddress[1] & 15) == 1;
- }
-
- public boolean isMCLinkLocal() {
- return (this.ipaddress[0] & 255) == 255 && (this.ipaddress[1] & 15) == 2;
- }
-
- public boolean isMCSiteLocal() {
- return (this.ipaddress[0] & 255) == 255 && (this.ipaddress[1] & 15) == 5;
- }
-
- public boolean isMCOrgLocal() {
- return (this.ipaddress[0] & 255) == 255 && (this.ipaddress[1] & 15) == 8;
- }
-
- public byte[] getAddress() {
- return (byte[])this.ipaddress.clone();
- }
-
- public int getScopeId() {
- return this.scope_id;
- }
-
- public NetworkInterface getScopedInterface() {
- return this.scope_ifname;
- }
-
- public String getHostAddress() {
- String var1 = numericToTextFormat(this.ipaddress);
- if (this.scope_ifname_set) {
- var1 = var1 + "%" + this.scope_ifname.getName();
- } else if (this.scope_id_set) {
- var1 = var1 + "%" + this.scope_id;
- }
-
- return var1;
- }
-
- public int hashCode() {
- if (this.ipaddress == null) {
- return 0;
- } else {
- int var1 = 0;
-
- int var4;
- for(int var2 = 0; var2 < 16; var1 += var4) {
- int var3 = 0;
-
- for(var4 = 0; var3 < 4 && var2 < 16; ++var2) {
- var4 = (var4 << 8) + this.ipaddress[var2];
- ++var3;
- }
- }
-
- return var1;
- }
- }
-
- public boolean equals(Object var1) {
- if (var1 != null && var1 instanceof Inet6Address) {
- Inet6Address var2 = (Inet6Address)var1;
-
- for(int var3 = 0; var3 < 16; ++var3) {
- if (this.ipaddress[var3] != var2.ipaddress[var3]) {
- return false;
- }
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isIPv4CompatibleAddress() {
- return this.ipaddress[0] == 0 && this.ipaddress[1] == 0 && this.ipaddress[2] == 0 && this.ipaddress[3] == 0 && this.ipaddress[4] == 0 && this.ipaddress[5] == 0 && this.ipaddress[6] == 0 && this.ipaddress[7] == 0 && this.ipaddress[8] == 0 && this.ipaddress[9] == 0 && this.ipaddress[10] == 0 && this.ipaddress[11] == 0;
- }
-
- static String numericToTextFormat(byte[] var0) {
- StringBuffer var1 = new StringBuffer(39);
-
- for(int var2 = 0; var2 < 8; ++var2) {
- var1.append(Integer.toHexString(var0[var2 << 1] << 8 & '\uff00' | var0[(var2 << 1) + 1] & 255));
- if (var2 < 7) {
- var1.append(":");
- }
- }
-
- return var1.toString();
- }
-
- private static native void init();
-
- private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
- if (this.scope_ifname_set) {
- this.ifname = this.scope_ifname.getName();
- }
-
- var1.defaultWriteObject();
- }
-
- static {
- init();
- }
- }
-